package com.long1008.controller.personnel;

import com.long1008.pojo.EmpRetire;
import com.long1008.pojo.Employee;
import com.long1008.pojo.RespBean;
import com.long1008.service.EmpService;
import com.long1008.service.PersonnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/personnel/retire")
public class EmpRetireController {

    @Autowired
    EmpService empService;

    @Autowired
    PersonnelService personnelService;

    @RequestMapping(value = "/addretire", method = RequestMethod.POST)
    public RespBean addRetire(EmpRetire empRetire){
        Employee employee = empService.getEmpById(empRetire.getEid());
        if(empService.getEmpById(empRetire.getEid())==null){
            return RespBean.error("员工号不存在");
        }
        if (!employee.getName().equals(empRetire.getEmpName())) {
            return RespBean.error("员工号与员工姓名不匹配！");
        }
        if(personnelService.addRetire(empRetire)==1 && empService.deleteEmpById(employee.getId().toString())){
            return RespBean.ok("离职成功!");
        }
        return RespBean.error("离职失败");
    }
}
